<?php

//defined('APP_PATH') or die();
include 'redir.php';
require_once ('Smarty-2.6.26/libs/Smarty.class.php');


class view {
    private static $objInstance = null;
    private $smarty;
    private $menuArray;
    private $contentArray;

    function __construct() {
        $this->smarty = new Smarty();
        $this->smarty->template_dir = 'views';
        $this->smarty->compile_dir = 'tmp';
        $this->iniMenuBar();
        
    }
    protected function iniMenuBar(){
        $this->menuArray=array(
            array('title'=>"Główna strona",'link'=>"/home",'active'=>false,'content'=>"mainPanel.tpl"),
            array('title'=>"List mailingowe",'link'=>"/mailing",'active'=>false,'content'=>"mailings.tpl"),
            array('title'=>"Użytkownicy",'link'=>"/users",'active'=>false,'content'=>"users.tpl"),
            array('title'=>"Grupy Użytkowników",'link'=>"/groups",'active'=>false,'content'=>"groups.tpl"),
            array('title'=>"Organizacje",'link'=>"/orgs",'active'=>false,'content'=>"orgs.tpl"),
            array('title'=>"Kategorie klientów",'link'=>"/category",'active'=>false,'content'=>"categories.tpl")
            );
    }

    public static function getInstance() {
        if (is_null(self::$objInstance)) {
            self::$objInstance = new self();
        }
        return self::$objInstance;
    }

    function loginPage() {
        $this->smarty->assign('title', 'Testowy Smarty');
        $this->smarty->display('login.tpl');
    }
    function showPage($index=0){
        $this->menuArray[$index]['active']=true;
        $this->smarty->assign('title', 'Mailing');
        $this->smarty->assign('menuBar', $this->menuArray);
        $this->smarty->assign('content', "mainPanel.tpl");
        $this->smarty->assign('user', $_SESSION['user']);
        $this->smarty->display('main.tpl');
    }
    function show(){
        $this->smarty->assign('title', 'Mailing');
        $this->smarty->assign('menuBar', $this->menuArray);
        $this->smarty->assign('content', "mainPanel.tpl");
        $this->smarty->assign('user', $_SESSION['user']);
        $this->smarty->display('main.tpl');
    }
    function error($msg){
        $this->smarty->assign('title', 'Mailing');
        $this->smarty->assign('menuBar', $this->menuArray);
        $this->smarty->assign('siteMissing', $msg);
        $this->smarty->assign('content', "error.tpl");
        $this->smarty->assign('user', $_SESSION['user']);
        $this->smarty->display('main.tpl');
    }
    function menuBar($param) {
        $activeArray=array();
        $activeArray[$param]='class="active"';
        return $activeArray;
    }
}

?>
